<?php

class Application_Form_Users extends Zend_Form
{

    public function init()
    {
        /* Form Elements & Other Definitions Here ... */
    	
    	$identity=Zend_Auth::getInstance()->getIdentity();
    	 
    	if($identity->idtypeusers=="premier responsable"){
    	
	    	$pere = new Zend_Form_Element_Select('pere');
	    	
	    	$pere->setLabel("Responsable");
	     	 
	    	$perereg=new Application_Model_DbTable_Users();
	    	$list =$perereg->fetchAll()->toArray();
	    	$pere->addMultiOption("","");
	    	foreach($list as $key => $value){
	    		$pere->addMultiOption($value['idusers'],$value['nom']." ".$value['prenom']);
	    		 
	    	}
    	}
    	
    	$delegation = new Zend_Form_Element_Checkbox('Delegation');
    	$delegation->setLabel('Delegation');
    	
    	$this->setName("Inscription");
    	 
    	$Nom = new Zend_Form_Element_Text('Nom');
    	$Nom->setRequired(true)

    	->setAttrib('class','validate[required] text-input');
    	$Nom->setLabel('Nom');
    	
    	
    	$email = new Zend_Form_Element_Text('email');
    	$email->setRequired(true)

    	->setAttrib('class','validate[required] text-input');
    	$email->setLabel('Adress Mail');
    	
    	
    	$tel = new Zend_Form_Element_Text('tel');
    	$tel->setRequired(true)

    	->setAttrib('class','validate[required] text-input');
    	$tel->setLabel('Tel');
    	
    	
    	$Prenom = new Zend_Form_Element_Text('Prenom');
    	$Prenom->setRequired(true)

    	->setAttrib('class','validate[required] text-input');
    	$Prenom->setLabel('Prenom');
    	
    	
    	$Login = new Zend_Form_Element_Text('Login');
    	$Login->setRequired(true)
    	->setAttrib('class','validate[required] text-input');
    	$Login->setLabel('Nom d\'utilisateur');

    	$motdepass = new Zend_Form_Element_Password('motdepasse');
    	$motdepass->setRequired(true)
    	->setAttrib('class','validate[required] text-input');
    	$motdepass->setLabel('Mot de passe');
    	
    	
    	$Regional= new Zend_Form_Element_Multiselect("Regional");
    	$Regional->setLabel("Regional") 
    	->addDecorator('HtmlTag',array('tag' => 'div', 'id' => 'diplomediv') );
    	$Regional->setAttrib("ondblclick", "AjaxLoading('geteltgov',this.value,'Regional')");
     
    	$Regionalreg=new Application_Model_DbTable_Governeras();
    	$Regionals=$Regionalreg->selectForOptions();
    	
    	foreach ($Regionals['data'] as $key => $value){
    		$Regional->addMultiOption($value['key'], ($value['value']));
    	}
    	
    	
    	$fonction = new Zend_Form_Element_Select('Fonction');
    	$fonction->setRequired(true);
    	$fonction->setLabel("Fonction");
    	
    	
    	 $fonctionreg=new Application_Model_DbTable_Fonctionresp();
    	$list =$fonctionreg->fetchAll()->toArray();
    	foreach($list as $key => $value){
    		$fonction->addMultiOption($value['idfonctionresp'],$value['idfonctionresp']);
    	
    	} 
    	
    	
    	$typeuser = new Zend_Form_Element_Select('type');
    	$typeuser->setRequired(true);
    	$typeuser->setLabel("Type utilisateur");
    	 
    	 
    	$typeuserreg=new Application_Model_DbTable_Typeusers();
    	$list =$typeuserreg->fetchAll()->toArray();
    	foreach($list as $key => $value){
    		$typeuser->addMultiOption($value['idtypeusers'],$value['idtypeusers']);
    		 
    	}
    	
    	$sendBt = new Zend_Form_Element_Submit('submit');
    	$sendBt->setLabel('Enregistrer');
    	if($identity->idtypeusers=="premier responsable"){
    	
    	$this->addElements(array($Nom,$Prenom,$pere,$delegation,$email,$tel,$Regional,$fonction,$Login,$motdepass,$typeuser,$sendBt));
    	
    	}else{
    		$this->addElements(array($Nom,$Prenom,$delegation,$email,$tel,$Regional,$fonction,$Login,$motdepass,$typeuser,$sendBt));
    		 
    	}
    }


}

